//
//  HomeDetailView.m
//  CarUser
//
//  Created by 王森林 on 2018/12/4.
//  Copyright © 2018年 王森林. All rights reserved.
//

#import "HomeDetailView.h"

@interface HomeDetailView()

@property (assign, nonatomic) HOME_DETAIL_TYPE showType;
@property (nonatomic, strong) UILabel *a_titleLabel;
@property (nonatomic, strong) UIButton *a_detaiBtn;
@property  (nonatomic, copy) void (^resultBlock)(id  response);
@end

@implementation HomeDetailView

- (instancetype)initWithType:(HOME_DETAIL_TYPE)type withBlock:(nonnull void (^)(id _Nonnull))result
{
    self = [super init];
    if (self) {
        self.showType = type;
        self.resultBlock = result;
        [self createUI];
    }
    return self;
}

-  (void)createUI
{
    [self removeAllSubviews];
    [self addSubview:self.a_titleLabel];
    [self addSubview:self.a_detaiBtn];
    [self createConstraint];
    switch (self.showType) {
        case HOME_DETAIL_TYPE_IMPORT:
            self.a_titleLabel.text = @"重点车型";
            break;
        case HOME_DETAIL_TYPE_NUMBER:
            self.a_titleLabel.text = @"热销排行";
            break;
        case HOME_DETAIL_TYPE_INSURANCE:
            self.a_titleLabel.text = @"保险服务";
            break;
        case HOME_DETAIL_TYPE_MAINTAIN:
            self.a_titleLabel.text = @"维修保养";
            break;
        case HOME_DETAIL_TYPE_SHOP:
        {
            self.a_titleLabel.text = @"加盟门店";
            self.a_detaiBtn.hidden = YES;
        }
            
            break;
            
        default:
            break;
    }
    
}

- (void)createConstraint
{
    [self.a_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(15);
        make.left.equalTo(self.mas_left).offset(15);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(18);
    }];
    
    [self.a_detaiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(15);
        make.right.equalTo(self.mas_right).offset(-15);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(18);
    }];
    
    
}

- (void)handleMoreAction
{
    if (self.resultBlock) {
        self.resultBlock(@"");
    }
    
    
}

- (UILabel *)a_titleLabel
{
    if (!_a_titleLabel) {
        _a_titleLabel = [UILabel new];
        _a_titleLabel.textColor = RGB(50, 50, 50);
        _a_titleLabel.font = FONT_SIZE(18);
    
    }
    return _a_titleLabel;
    
}

- (UIButton *)a_detaiBtn
{
    if (!_a_detaiBtn) {
        _a_detaiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_a_detaiBtn setTitle:@"详情" forState:UIControlStateNormal];
        [_a_detaiBtn setImage:IMG(@"home_arrow") forState:UIControlStateNormal];
        [_a_detaiBtn setTitleColor:Common_TextLowColor forState:UIControlStateNormal];
        _a_detaiBtn.titleLabel.font = FONT_SIZE(14);
        [_a_detaiBtn addTarget:self action:@selector(handleMoreAction) forControlEvents:UIControlEventTouchUpInside];
//        _a_detaiBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
//        //    UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
        [_a_detaiBtn setTitleEdgeInsets:UIEdgeInsetsMake(0 ,0, 0.0,0)];//文字距离上边框的距离增加imageView的高度，距离左边框减少imageView的宽度，距离下边框和右边框距离不变
       [_a_detaiBtn setImageEdgeInsets:UIEdgeInsetsMake( 0, 0,0.0, -90)];//图片距离右边框距离减少图片的宽度，其它不边
    }
    return _a_detaiBtn;
    
}

@end
